📜 [專欄新文章] Gas Efficient Card Drawing in Solidity
✍️ Ping Chen
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Assign random numbers as the index of newly minted NFTs
Scenario
The fun of generative art NFT projects depends on randomness. The industry standard is “blind box”, where both the images’ serial number and the NFTs’ index are predetermined but will be shifted randomly when the selling period ends. (They call it “reveal”) This approach effectively solves the randomness issue. However, it also requires buyers to wait until the campaign terminates. What if buyers want to know the exact card right away? We’ll need a reliable onchain card drawing solution.
The creator of Astrogator🐊 isn’t a fan of blind boxes; instead, it thinks unpacking cards right after purchase is more interesting.
Spec
When initializing this NFT contract, the creator will determine the total supply of it. And there will be an iterable function that is randomly picking a number from the remaining pool. The number must be in range and must not collide with any existing ones.
Our top priority is accessibility/gas efficiency. Given that gas cost on Ethereum is damn high nowadays, we need an elegant algorithm to control gas expanse at an acceptable range.
Achieving robust randomness isn’t the primary goal here. We assume there’s no strong financial incentive to cheat, so the RNG isn’t specified. Implementers can bring their own source of randomness that they think is good enough.
Implementation
Overview
The implementation is pretty short and straightforward. Imagine there’s an array that contains all remaining(unsold) cards. When drawIndex() is called, it generates a (uniform) random seed to draw a card from the array, shortens the array, and returns the selected card.
Algorithm
Drawing X cards from a deck with the same X amount of cards is equal to shuffling the deck and dealing them sequentially. It’s not a surprise that our algorithm is similar to random shuffling, and the only difference is turning that classic algo into an interactive version.
A typical random shuffle looks like this: for an array with N elements, you randomly pick a number i in (0,N), swap array[0] and array[i], then choose another number i in (1,N), swap array[1] and array[i], and so on. Eventually, you’ll get a mathematically random array in O(N) time.
So, the concept of our random card dealing is the same. When a user mints a new card, the smart contract picks a number in the array as NFT index, then grabs a number from the tail to fill the vacancy, in order to keep the array continuous.
Tweak
Furthermore, as long as the space of the NFT index is known, we don’t need to declare/initialize an array(which is super gas-intensive). Instead, assume there’s such an array that the n-th element is n, we don’t actually initialize it (so it is an array only contains “0”) until the rule is broken.
For the convenience of explanation, let’s call that mapping cache. If cache[i] is empty, it should be interpreted as i instead of 0. On the other hand, when a number is chosen and used, we’ll need to fill it up with another unused number. An intuitive method is to pick a number from the end of the array, since the length of the array is going to decrease by 1.
By doing so, the gas cost in the worst-case scenario is bound to be constant.
Performance and limitation
Comparing with the normal ascending index NFT minting, our random NFT implementation requires two extra SSTORE and one extra SLOAD, which cost 12600 ~ 27600 (5000+20000+2600) excess gas per token minted.
Theoretically, any instantly generated onchain random number is vulnerable. We can restrict contract interaction to mitigate risk. The mitigation is far from perfect, but it is the tradeoff that we have to accept.
ping.eth
Gas Efficient Card Drawing in Solidity was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有23部Youtube影片,追蹤數超過15萬的網紅ロイドごはん,也在其Youtube影片中提到,『山岡家』の限定ラーメン!『ラーメン山岡家』にお邪魔して「ホタテ塩とんこつ」をいただきました。こちらは基本的に6月半ば迄の予定だそうですが、各店舗での売れ行きによっては前倒しでの終了ありとのこと。トッピングとしてホタテが入っているだけでなくベースのスープにホタテエキスがプラスされているそう。また、今...
time limitation 在 孫怡琳 Facebook 的最佳貼文
跟著怡琳看世界 34
How does the Paralympic classification system work?
帕運的分類系統如何運作?
classification 分類
athlete 運動員
cornerstone 基石/基礎
eligible 有資格的
impairment 損傷/損害
prowess 高超的技能
Like the Olympics, the Paralympics are taking place a year after originally planned because of the delay caused by the coronavirus pandemic.
如同奧運,由於新冠肺炎大流行造成延誤,帕運比原計畫晚了一年舉行。
According to the International Paralympic Committee (IPC), there are 2550 male and 1853 female athletes taking part in Games, which run from August 24 to September 5.
根據國際帕運委員會(IPC)的統計,從8月24日到9月5日舉行的帕運,有2550名男性運動員和1853名女性運動員參與。
"Classification is the cornerstone of the Paralympic Movement, it determines which athletes are eligible to compete in a sport and how athletes are grouped together for competition,' says the IPC.
IPC說:「分類是帕運的基石,它決定哪些運動員有資格參加某項運動,以及如何分組參加比賽。」
What makes a Paralympian?
是什麼造就一位帕運運動員?
Paralympians are grouped together by the "degree of activity limitation resulting from the impairment," according to the IPC.
根據IPC的說法,帕運運動員是根據"因損傷導致的活動受限程度"來分組的。
As different sports require different physical demands, the IPC says the classification process "aims to minimize the impact of the impairment on athletes' performance" so that their athletic prowess is showcased.
由於不同的運動項目需要不同的身體需求,IPC表示分類的過程中,旨在"最大限度減少損傷對運動員表現造成的影響",以便展示他們高超的運動技能。
What do the classes in each sport mean?
每項運動的分類代表什麼?
The class groups athletes with similar athletic limitations so that they can compete to similar levels, but does not necessarily have to solely group athletes with the same eligible impairment.
分類會將具有相似運動限制的運動員分組在一起,讓他們以相似的水平競爭,但不一定必須將具有相同缺陷條件的運動員分在一起。
Because some impairments progress over time, athletes can change classification over time.
由於一些損傷會隨著時間流逝而有進展,因此運動員可以隨著時間而更改分類。
資料來源
https://edition.cnn.com/2021/08/24/sport/paralympics-classification-explainer-spt-intl/index.html
time limitation 在 Facebook 的最佳貼文
Reinventing British - back at Jaan for the third time for their new menu and wow, it seems that Chef Kirk has improved tremendously over the years! This new menu features a lot of Jaan’s specialities, with a little twist (this time, a cleaner one) so we were still excited to still be able to have them!
Starters - plated in ascending order, we were told to start from the bottom (Cucumber meringue) making our way to the top (goose mousse) which was 10/10
Finishing off with the roast leek & potato soup that was served with a side of pastry. DAYUM. The pastry was 😍
For the sake of the word limitation, I highly recommend Jaan for consistent good food, nice selection of wines, cheeses and if you’re a fan of bread 🥖, eggs (eggs hen is bomb), langoustine and Wagyu (melt in your mouth for real) …I think Jaan has perfected them all.
With the stunning views and impeccable service, it’s a 9/10 ⭐️ for both Matt & I, and I think the price tag of $288++ per pax is well-worth it. Unlike some fine dining places, you never leave Jaan hungry!
#mongabongeats #jaan #jaansg #sgfoodies #Mnmcouple
time limitation 在 ロイドごはん Youtube 的最佳解答
『山岡家』の限定ラーメン!『ラーメン山岡家』にお邪魔して「ホタテ塩とんこつ」をいただきました。こちらは基本的に6月半ば迄の予定だそうですが、各店舗での売れ行きによっては前倒しでの終了ありとのこと。トッピングとしてホタテが入っているだけでなくベースのスープにホタテエキスがプラスされているそう。また、今回の限定のために平打ち麺使用しています。こうした味へのこだわりだけでなく、JAF会員証提示や半券を集めると受けられるサービスなど、リピーターや車でいらっしゃるお客様目線のサービスがあるのも「山岡家」の特徴かもしれませんね。「ガツンと来て、くせになる。」山岡家、早速ご覧ください!
*山岡家では時短要請がある場合、国からの指定時間の20分前が最終調理開始時間になるとのこと(同社HPより)。
*感染対策を徹底して撮影を行っています。
*撮影に際しては、お店の方や周りのお客様に充分配慮して撮影をおこなっています。
Limited ramen from the "Yamaokaya"! I visited the "Ramen Yamaokaya" and received "scallop salt tonkotsu". It seems that this is basically scheduled until the middle of June, but depending on the sales at each store, it may end ahead of schedule. Not only does it contain scallops as a topping, but it also has scallop extract added to the base soup. In addition, we are using flat noodles for this limitation. In addition to this commitment to taste, the Yamaokaya may also have services from the perspective of repeaters and customers who come by car, such as the services that can be received by presenting a JAF membership card and collecting stubs. "Come with me and become a habit." Yamaokaya, please have a look!
* If the Yamaoka-ya requests a shorter time, the final cooking start time will be 20 minutes before the designated time from the government (from the company's website).
* We take thorough measures against infection.
* When shooting, we give due consideration to the shop and customers around us.
いつもありがとうございます!( ´ ▽ ` )
高評価&チャンネル登録もよろしくお願いいたします!
#ラーメン #山岡家 #期間限定 #ロイドごはん #フラメンコロイド
—————《サブチャンネル》—————————————
【サブチャンネルもよろしくお願いします!】
メロンシートジャーニー
https://www.youtube.com/channel/UCwNlBAUziFWkJZFY_u3t65A
フラメンコロイド
https://www.youtube.com/channel/UCsFJHNg3SR41R2a3vctUInw
🍀「ロイドごはん」公式LINE
https://lin.ee/ow4OdaV
—————《本日の店舗情報》—————————————————
『山岡家』
https://www.yamaokaya.com
—————《ロイドごはんのおすすめ動画 ROIDGOHANs’ Recommended video》———————————
78才おじいちゃん屋台ラーメンの朝『幸っちゃん』夜明けの銀座 【飯テロ】Old Style Ramen yatai Japanese Street Food
https://youtu.be/YHiWYvhxUI4
【家系ラーメン特集!】
https://www.youtube.com/playlist?list=PL6yW17uB9uIVUmOS8qnXrRwcBu8W-uRYZ
神回【ラーメン二郎の貴重映像】全増しが出来るまで一部始終を大公開!【ラーメン二郎 ひばりヶ丘店】ramen
https://youtu.be/mBFcdMHyaxA
巨大塊肉に挑戦!【いきなりステーキ】2人で1.5キロの結果は?【飯テロ】
https://youtu.be/lxn_oa-rCvQ
神技!いつもびっくりするよ!【がんちゃん】お好み焼きの名店に感動!【飯テロ】× フラメンコロイド 広島県
https://youtu.be/8q_j5QX4-vg
—————《twitter》—————————————————————
★ロイドごはん
https://twitter.com/roidgohan
★メロンシート
https://twitter.com/meloncito310
★フラメンコロイド
https://twitter.com/flamenkoroid
—————《instagram》———————————————————-
★ロイドごはん
https://www.instagram.com/roidgohan
★メロンシート
https://www.instagram.com/satoshimelo...
★フラメンコロイド
https://www.instagram.com/flamenkoroid
—————《各サイトの情報》—————————————————
★ロイドwalker《人生をドラマチックに彩る旅とグルメと温泉図鑑》
https://ramenjapan.net/
★メロンシート《フラメンコギターの世界一の旅》
https://pordiotama3.xsrv.jp
★フラメンコロイド 《フラメンコロイドの神話と伝説》
https://flamenkoroid.net
time limitation 在 Zarul Umbrella Youtube 的最讚貼文
Penerangan mengenai apa itu epaulets, flight time limitation, kejadian enjin terbakar penerbangan UA328 dan pendaratan di lapangan terbang Kathmandhu
time limitation 在 LYDIA劉敬雯 Official Youtube 的最佳貼文
狂舞兒送俾大家嘅禮物,幫大家打打氣❤️
“When life is hard, KEEP ON DANCING!"
8年,大家都長大了,各自行緊自己嘅路。
但每次聚埋,都笑到有腹肌。今次用《狂舞派3》插曲“KEEP ON DANCING”黎拍條跳舞片,個個即刻幫手,幾忙都抽時間,真係熱血到呢!!!
就用呢條片去紀念我地嘅成長啦,多謝你《狂舞派》,多謝你黃修平導演!
大家繼續支持我地, 我地感激大家多年來開支持, LET’S DANCE~
⭐️Cast⭐️
LOKMAN
LYDIA
BOBBY
LEANDER
JANICE
TASHA
CHUTIN
BABYJOHN
?Special Appearance?
JAN CURIOUS
DEE GOR
CHERRY
Video Director: LYDIA LAU
Videography: JUSTIN LAU
Editing: JUSTIN LAU | KAN HUI
Graphic Design: JIMMY LAM
Make-up: BILL CHAN | JANICE FAN | YVONNE YEUNG
Venue Sponsor: FUNKYTOWN DANCE STUDIO | RAIDER
Special Thanks: KAKA | NICOLAS WONG | PRISCILLA CHAN
[KEEP ON DANCING]
Music Compose | Arrangement | Produced By: DAY TAI
Lyrics By: LYDIA LAU
Performed By: JAN CURIOUS & LYDIA LAU
Bass: CHAN SIU KEI
Trumpet: LU SAI YU
Trombone: LI LAP WANG
Assistant: EASON YH CHAN
OP: DDOME PRODUCTIONS LIMITED
Hey what’s up?
How you doing today?
Well, tell me whatcha thinking?
This is the way I live
The rhythm when I breathe
Follow me I’ll let your mind be free
There will be no limitation
No time for hesitation
Alright now, c’mon let music take you away
You’ll hear the music bumping
You’ll hear your heartbeat rising
KEEP ON DANCING, find out what’s been missing
I’ll keep on waving turning
I’ll keep on syncopating
KEEP ON DANCING, show us what you’re feeling
It feels so right
When we can let go what’s on your mind
Right here tonight
It’s now or it’s never
You’ll hear the music bumping
You’ll hear your heartbeat rising
KEEP ON DANCING, find out what’s been missing
I’ll keep on waving turning
I’ll keep on syncopating
KEEP ON DANCING, show us what you’re feeling
Hey you, don’t lose your shine
Ain’t nothing matter if you start believing tonight
Let’s KEEP ON DANCING
Let’s KEEP ON DANCING
It might just sound crazy
It’s between you and me
I am powered by musicality
Yeah you know it’s time
To answer the call together tonight
It’s electrified
Dance with me tonight
You’ll hear the music bumping
You’ll hear your heartbeat rising
KEEP ON DANCING, find out what’s been missing
I’ll keep on waving turning
I’ll keep on syncopating
KEEP ON DANCING, show us what you’re feeling
Clap, Clap, Clap, Clap your hands
Clap, Clap, Clap, Clap your hands
Shake it off now, Shake it off now
Let’s dance now!
time limitation 在 time limitation - 英中– Linguee词典 的相關結果
大量翻译例句关于"time limitation" – 英中词典以及8百万条中文译文例句搜索。 ... <看更多>
time limitation 在 time limit; time limitation - 時限 - 國家教育研究院雙語詞彙 的相關結果
出處/學術領域, 中文詞彙, 英文詞彙. 學術名詞 海事, 時限, time limit; time limitation. 學術名詞 心理學名詞, 時限, time limit. 學術名詞 心理學名詞 ... <看更多>
time limitation 在 time limit中文(繁體)翻譯:劍橋詞典 的相關結果
We've set a time limit of ten minutes for each child's turn on the trampoline. 我們限定每個孩子在蹦蹦床上只能玩十分鐘。 There's a 3-hour time limit on ... ... <看更多>